package com.quest.space.poker.base.bean;

import com.quest.space.poker.base.enums.HttpCodeEnum;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success(T t){
        Result<T> result = new Result();
        result.setCode(HttpCodeEnum.SUCCESS.getCode());
        result.setMessage("success");
        result.setData(t);
        return result;
    }

    public static <T> Result<T> fail(T t){
        Result<T> result = new Result();
        result.setCode(HttpCodeEnum.FAIL.getCode());
        result.setMessage("fail");
        result.setData(t);
        return result;
    }

    public static <T> Result<T> build(HttpCodeEnum code){
        Result<T> result = new Result();
        result.setCode(code.getCode());
        result.setMessage(code.getMsg());
        return result;
    }

    public static <T> Result<T> build(HttpCodeEnum code, T data){
        Result<T> result = new Result();
        result.setCode(code.getCode());
        result.setMessage(code.getMsg());
        result.setData(data);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
